package com.su.test;

import com.su.bean.Account;
import com.su.bean.Role;
import com.su.bean.User;
import com.su.bean.UserRole;
import com.su.dao.AccountMapper;
import com.su.dao.RoleMapper;
import com.su.dao.UserMapper;
import com.su.dao.UserRoleMapper;
import com.su.service.UserService;
import lombok.Data;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.InputStream;
import java.util.Date;
import java.util.List;

/**
 * @Author:宿世新
 * @Dte:2022/4/8
 */
public class test {
    @Test
    public void test01() throws Exception {
        String resource = "sqlMapConfig.xml";
        InputStream is = null;
        try {
            is = Resources.getResourceAsStream(resource);
        } catch (Exception e) {
            e.printStackTrace();
        }
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
        SqlSession sqlSession = sqlSessionFactory.openSession(true);
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
        AccountMapper accountMapper = sqlSession.getMapper(AccountMapper.class);
        UserRoleMapper userRoleMapper = sqlSession.getMapper(UserRoleMapper.class);
        List<UserRole> userRoles = userRoleMapper.findUserJoinUserRole();
        RoleMapper roleMapper = sqlSession.getMapper(RoleMapper.class);
        List<Role> roles = roleMapper.userJoinUserRoleJoinRoleSQL02();
        for (Role role : roles) {
            System.out.println(role);
        }
//        List<Role> userJoinUser = userRoles.UserJoinUserRoleJoinRoleSQL();
//        for (Account account : userJoinUser) {
//            System.out.println(account);
//            System.out.println(account.getUser());
//        }
//        for (UserRole userRole : userJoinUser) {
//            System.out.println(userRole.getUser());
//            System.out.println(userRole.getRID());
//        }
//        for (UserRole userRole : userJoinUser.getUserRole()) {
//            System.out.println(userRole);
//        }
//        for (Role role : userJoinUser) {
//            System.out.println(role.getUser());
//            System.out.println(role.getROLE_NAME() + "------" + role.getROLE_DESC());
//            System.out.println("----------------------------------");
//        }
    }

    @Test
    public void test02() throws Exception {
        String resource = "sqlMapConfig.xml";
        InputStream is = null;
        try {
            is = Resources.getResourceAsStream(resource);
        } catch (Exception e) {
            e.printStackTrace();
        }
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
        SqlSession sqlSession = sqlSessionFactory.openSession(true);
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
        AccountMapper accountMapper = sqlSession.getMapper(AccountMapper.class);
        UserRoleMapper userRoleMapper = sqlSession.getMapper(UserRoleMapper.class);
        List<UserRole> userRoles = userRoleMapper.findUserJoinUserRole();
        for (UserRole userRole : userRoles) {
            System.out.println(userRole);
        }
    }

    @Test
    public void test03() throws Exception {
        String resource = "sqlMapConfig.xml";
        InputStream is = null;
        try {
            is = Resources.getResourceAsStream(resource);
        } catch (Exception e) {
            e.printStackTrace();
        }
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
        SqlSession sqlSession = sqlSessionFactory.openSession(true);
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
        AccountMapper accountMapper = sqlSession.getMapper(AccountMapper.class);
        UserRoleMapper userRoleMapper = sqlSession.getMapper(UserRoleMapper.class);
        List<UserRole> userRoles = userRoleMapper.findUserJoinUserRole();
        List<UserRole> userRoles02 = userRoleMapper.findUserJoinUserRole();
        System.out.println(userRoles == (userRoles02));

    }
}
